package com.kaoshi.management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kaoshi.management.pojo.XtSettingsInformationManagement;
import com.kaoshi.management.pojo.XtSlideshow;
import com.kaoshi.management.mapper.XtSlideshowMapper;
import com.kaoshi.management.service.XtSlideshowService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-10-30
 */
@Service
public class XtSlideshowServiceImpl extends ServiceImpl<XtSlideshowMapper, XtSlideshow> implements XtSlideshowService {

    @Autowired
    private XtSlideshowMapper xtSlideshowMapper;

    @Override
    public Page<XtSlideshow> findAll(Integer current, Integer pageSize, XtSlideshow xtSlideshow) {
        Page<XtSlideshow> page = new Page<>(current, pageSize);

        LambdaQueryWrapper<XtSlideshow> wrapper = new LambdaQueryWrapper<>();

        if (xtSlideshow.getBannerName() != null) {
            wrapper.eq(XtSlideshow::getBannerName, xtSlideshow.getBannerName());
        }
        if (xtSlideshow.getStartDate() != null && xtSlideshow.getEndDate() != null) {
            // 假设 XtSettingsInformationManagement 有一个获取日期的方法 getDate()
            wrapper.between(XtSlideshow::getPublishTime, xtSlideshow.getStartDate(), xtSlideshow.getEndDate());
        }
//        if (xtSlideshow.getStatus() != null) {
//            wrapper.eq(XtSlideshow::getStatus, xtSlideshow.getStatus());
//        }

        return xtSlideshowMapper.selectPage(page, wrapper);
    }


}

